/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commonClasses.Authentication;

import commonClasses.*;
import commonClasses.commonInterfaces.AuthenticationIntf;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Pozytywny!
 */
public class Authentication implements AuthenticationIntf {

    public boolean authenticate(String hash, ArrayList<String> nothashed) {


        try {
            Iterator<String> it = nothashed.iterator();
            while (it.hasNext()) {
                String nh = it.next();
                if (AeSimpleMD5.MD5(nh).equals(hash)) {
                    return true;
                }
            }

            return false;

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        return false;
    }

    public String encode(String ident) {


        try {
            return AeSimpleMD5.MD5(ident);

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }

    }

    public static void main(String args[]) {

        try {
            Utils.write(AeSimpleMD5.MD5("asdasdfasdfasdfasdfasdf"));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }


    }
}
